package com.xhs.controller;

import com.xhs.design.adapter.impl.ApiAdapterImpl;
import com.xhs.dto.request.GetInfoAdapterRequest;
import com.xhs.message.ReturnResult;
import com.xhs.utils.ContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @desc: 适配器模式
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2022/12/5 10:58
 * @version: JDK 1.8
 */
@RestController
@RequestMapping("/adapter")
public class AdapterController {

    @Autowired
    private ApiAdapterImpl apiAdapter;

    /**
     * 获取用户信息
     *
     * @param infoRequest
     * @return
     */
    @PostMapping("/getInfo")
    public ReturnResult<String> getInfo(@RequestBody GetInfoAdapterRequest infoRequest) {
        String adapter = infoRequest.getAdapter();
        Object object = ContextUtils.getBean(adapter);
        Object service = apiAdapter.doService(null, object);
        String string = service.toString();
        return ReturnResult.success(string);
    }
}
